﻿
@inject IRoleService rService
@model RoleEntity

@{

    ViewData["Title"] = "角色 编辑";
    Layout = "../Shared/_Layout.cshtml";

}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content text-center p-md">
                    <form id="dynamic-form" asp-action="Edit" method="post" class="form-horizontal" role="form">
                        <div asp-validation-summary="@ValidationSummary.All" class="text-danger"></div>
                        <input type="hidden" asp-for="RoleId" />
                        <div class="form-group">
                            <label asp-for="RoleKey" class="col-md-3 control-label text-right"> 角色标识</label>
                            <div class="col-md-9  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">*</span>
                                    <input asp-for="RoleKey" class="form-control" validate="{required:true  ,maxlength:50   }" />
                                </div>
                                <span asp-validation-for="RoleKey" class="text-danger"></span>
                            </div>

                        </div>
                        <div class="form-group">
                            <label asp-for="RoleName" class="col-md-3 control-label text-right"> 角色名称</label>
                            <div class="col-md-9  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">*</span>
                                    <input asp-for="RoleName" class="form-control" validate="{required:true  ,maxlength:50   }" />
                                </div>
                                <span asp-validation-for="RoleName" class="text-danger"></span>
                            </div>

                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label text-right"></label>
                            <div class="col-md-9 text-left">
                                <div class="i-checks ">
                                    <label asp-for="IsSystem"> <input tabindex="3" asp-for="IsSystem" type="checkbox">  是否系统 </label>
                                </div>
                            </div>

                        </div>
                        <div class="form-group">
                            <label asp-for="ParentId" class="col-md-3 control-label text-right"> 上级角色</label>
                            <div class="col-md-9  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon">*</span>
                                    <select id="ParentId" name="ParentId" class="select2">
                                        <option value="">&nbsp;</option>
                                        @{
                                            List<RoleEntity> lstAll = rService.GetAll();
                                            if (lstAll != null && lstAll.Count > 0)
                                            {
                                                foreach (var pEntity in lstAll)
                                                {
                                                    if (pEntity.RoleId != Model.RoleId)
                                                    {
                                                        @Html.Raw("<option value=\"" + pEntity.RoleId + "\" " + (pEntity.RoleId == Model.ParentId ? "selected" : "") + ">" + pEntity.RoleName + "</option>")
                                                    }

                                                }
                                            }
                                        }
                                    </select>

                                </div>
                                <span asp-validation-for="ParentId" class="text-danger"></span>
                            </div>

                        </div>
                        <div class="form-group">
                            <label asp-for="Remark" class="col-md-3 control-label text-right"> 备注</label>
                            <div class="col-md-9  text-left">
                                <div class="input-group m-b">
                                    <span class="input-group-addon"></span>
                                    <input asp-for="Remark" class="form-control" validate="{required:false  ,maxlength:200   }" />
                                </div>
                                <span asp-validation-for="Remark" class="text-danger"></span>
                            </div>

                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <a class="btn btn-white" asp-action="index">返  回</a>

                                <button class="btn btn-primary" type="submit">保存</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script type="text/javascript">
        $(function () {
            $(document).ready(function () {
                $(".form-horizontal").CustomForm({
                    isValidate: true,
                    isTable: false
                });

                $(".form-horizontal").submit(function () {
                    if (!$(".form-horizontal").valid()) {
                        return false;
                    }
                });
            });
        });
    </script>
}